﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Mail;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        for(int i=1;i<=31;i++)
        {
             NgayS.Items.Add(new ListItem(i.ToString(),i.ToString()));
        }
        for (int i = 1; i <= 12; i++)
        {
            ThangS.Items.Add(new ListItem(i.ToString(), i.ToString()));
        }
        for (int i = 1970; i <= 2008; i++)
        {
            NamS.Items.Add(new ListItem(i.ToString(), i.ToString()));
        }
    }
    protected void DangKy_Click(object sender, EventArgs e)
    {
       

        ShoppingDataContext db = new ShoppingDataContext();
        ACCOUNT myAccount = new ACCOUNT();
        myAccount.username = this.Ten_DN.Text;
        myAccount.password = this.Mat_Khau.Text;
        myAccount.Role = 1;
        db.ACCOUNTs.InsertOnSubmit(myAccount);

        var member = from p in db.MEMBERs
                     select p;
        int temp=1;
        int flag1 = 0;
        int flag=1;
        int ProId=0;
        string tam = "MB";
        while (flag != 0)
        {
            foreach (var mem in member)
            {
                string id = mem.MemberID.Substring(2,4);
                ProId = int.Parse(id);
                if (ProId == temp)
                {
                    temp++;
                    flag1 = 0;
                    break;
                }

                flag1 = 1;                     
            }
            if (flag1 == 1)
            {
                flag = 0;
                ProId = temp;
            }
            
        }
        for(int i=1;i<=4-ProId.ToString().Length;i++)
        {
            tam = tam + "0";
        }
        tam = tam + ProId.ToString();
        MEMBER myMember = new MEMBER();
        myMember.MemberID = tam;
        myMember.username = this.Ten_DN.Text;
        myMember.Fullname = this.Ho_Ten.Text;
        myMember.birthday = new DateTime(int.Parse(this.NamS.Text), int.Parse(this.ThangS.Text),
                                         int.Parse(this.NgayS.Text));
        myMember.phone = this.Phone.Text;
        myMember.email = this.Email.Text;
        myMember.address = this.Address.Text;
        db.MEMBERs.InsertOnSubmit(myMember);
        db.SubmitChanges();

    }
}
